# -*- coding: utf-8 -*-
def login():

    rows = db( db.golfer.emailAddress == request.vars.emailAddress ).select()

    responseDict = dict()

    if( len( rows ) ):

        if( rows[0].password == request.vars.password ):

            session.golferId = responseDict['id'] = rows[0].id

        else:
        
            responseDict['error'] = 'Invalid Login.'

    else:

        session.golferId = responseDict['id'] = db.golfer.insert( **request.vars )
        
    return response.json( responseDict )


def logout():

    session.golferId = ''

    return response.json( dict() )
